﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WebAssertTestLibrary.Core;

namespace WebAssert.Tests
{
    [TestClass]
    public class XhtmlValidatorTests
    {
        [TestMethod]
        public void XhtmlValidator_IsValidHtml_ReturnsTrueForValidHtml()
        {
            // Arrange
            const string html = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" +
                                "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">" + 
                                "  <head>" +
                                "    <title>Test valid document</title>" +
                                "  </head> " +
                                "  <body>" +
                                "    <div>This is a test</div>" + 
                                "  </body>" +
                                "</html>";
            var validator = new XhtmlValidator();

            // Act
            var result = validator.IsValidHtml(html);

            // Assert
            Assert.IsTrue(result.IsValid);
        }

        [TestMethod]
        public void XhtmlValidator_IsValidHtml_ReturnsFalseForInvalidHtml()
        {
            // Arrange
            const string html = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" +
                                "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">" +
                                "  <head>" +
                                "    <title>Test invalid document</title>" +
                                "  </head> " +
                                "  <body>" +
                                "    <div>This is a test" + // Missing closing </div> tag
                                "  </body>" +
                                "</html>";
            var validator = new XhtmlValidator();

            // Act
            var result = validator.IsValidHtml(html);

            // Assert
            Assert.IsFalse(result.IsValid);
        }

        [TestMethod]
        public void XhtmlValidator_ReturnsValidHtml_ReturnsTrueForUrlOfValidPage()
        {
            // Arrange
            const string url = "http://www.w3.org";
            var validator = new XhtmlValidator();

            // Act
            var result = validator.ReturnsValidHtml(url);

            // Assert
            Assert.IsTrue(result.IsValid);
        }

        [TestMethod]
        public void XhtmlValidator_ReturnsValidHtml_ReturnsFalseForUrlOfInvalidPage()
        {
            // Arrange
            const string url = "http://www.codeplex.com";
            var validator = new XhtmlValidator();

            // Act
            var result = validator.ReturnsValidHtml(url);

            // Assert
            Assert.IsFalse(result.IsValid);
        }
    }
}